package cn.myeasyai.util;

import org.dromara.easyai.matrixTools.Matrix;
import org.nd4j.linalg.api.ndarray.INDArray;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fushoujiang
 */
public class MatrixUtil {
    //矩阵转LIST<Float>
    public static List<Float> matrixToFloatList(Matrix matrix) throws Exception {
        List<Float> list = new ArrayList<>();
        int x = matrix.getX();
        int y = matrix.getY();
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                list.add((float)matrix.getNumber(i, j));
            }
        }
        return list;
    }
    public static List<Float> matrixToFloatList(INDArray matrix)  {
        float[] floatArray = matrix.toFloatVector();
        List<Float> floatList = new ArrayList(floatArray.length);
        for(int i = 0; i < floatArray.length; i++) {
            float f = floatArray[i];
            floatList.add(f);
        }
        return floatList;
    }
}
